package com.efast.dmom.aps.datahandlers;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.efast.cafe.framework.util.SpringWebUtils;
import com.efast.dmom.aps.bean.RouteOperation;
import com.efast.dmom.aps.dao.RouteOperationDao;
import com.efast.dmom.aps.entity.RouteOperationEntity;
import com.efast.dmom.aps.util.TimeUtil;

/**
 * 
 * @author WJ
 * @Date 2020年2月17日
 *
 */
@Component
public class RouteOperationDataHandler {

	@Autowired
	private RouteOperationDao routeOperationDao;

	public RouteOperation getByCode(String operationCode) {
		RouteOperation routeOperation = new RouteOperation();
		routeOperation.setInnerData(routeOperationDao.getByCode(operationCode));
		return routeOperation;
	}

	public RouteOperation getByName(String name) {
		RouteOperation routeOperation = new RouteOperation();
		routeOperation.setInnerData(routeOperationDao.getByName(name));
		return routeOperation;
	}

	public void save(RouteOperation obj) {
		if (obj.getInnerData() != null) {
			obj.getInnerData().setSiteId(DataHandlerUtils.getSiteId());
			obj.getInnerData().setCreationTime(TimeUtil.getLocalDateTime());
			obj.getInnerData().setCreationTimeZone(TimeUtil.getLocalTimeZone());
			obj.getInnerData().setCreator(SpringWebUtils.getRequestUser());
			obj.getInnerData().setLastModifiedTime(TimeUtil.getLocalDateTime());
			obj.getInnerData().setLastModifiedTimeZone(TimeUtil.getLocalTimeZone());
			obj.getInnerData().setLastModifier(SpringWebUtils.getRequestUser());
//			obj.getInnerData().setCreationPid(DataHandlerUtils.getDmomPid());
//			obj.getInnerData().setLastModifiedPid(DataHandlerUtils.getDmomPid());
			obj.getInnerData().setRowStatus(1);
			obj.getInnerData().setRowTrxId(1);
			routeOperationDao.save(obj.getInnerData());
		}
	}

	public RouteOperation getById(long id) {
		RouteOperation routeOperation = new RouteOperation();
		routeOperation.setInnerData(routeOperationDao.getById(id));
		return routeOperation;
	}

	public void update(RouteOperation obj) {
		if (obj.getInnerData() != null) {

			obj.getInnerData().setLastModifiedTime(TimeUtil.getLocalDateTime());
			obj.getInnerData().setLastModifier(SpringWebUtils.getRequestUser());
			obj.getInnerData().setLastModifiedTimeZone(TimeUtil.getLocalTimeZone());
//			obj.getInnerData().setLastModifiedPid(DataHandlerUtils.getDmomPid());

			routeOperationDao.update(obj.getInnerData());
		}
	}

	public void delete(RouteOperation obj) {
		if (obj.getInnerData() != null) {

			obj.getInnerData().setLastModifiedTime(TimeUtil.getLocalDateTime());
			obj.getInnerData().setLastModifier(SpringWebUtils.getRequestUser());
			obj.getInnerData().setLastModifiedTimeZone(TimeUtil.getLocalTimeZone());
//			obj.getInnerData().setLastModifiedPid(DataHandlerUtils.getDmomPid());

			routeOperationDao.delete(obj.getInnerData());
		}

	}

	public List<RouteOperation> getAllRouteOperation() {
		List<RouteOperationEntity> entityList = routeOperationDao.getAllRouteOperation();
		List<RouteOperation> routeOperationList = new ArrayList<RouteOperation>();
		if (entityList != null && entityList.size() > 0) {
		for (RouteOperationEntity entityData:entityList) {
			RouteOperation routeOperation=new RouteOperation();
			routeOperation.setInnerData(entityData);
			routeOperationList.add(routeOperation);
		}
		return routeOperationList;
		}
		return null;
	}

}
